package org.kleathome.dcpu16;

import org.kleathome.dcpu16.emulator.Emulator;

public class DCPU16Literal extends DCPU16Value
{
	protected char _value;
	protected boolean readNext = false;

	public DCPU16Literal(char value)
	{
		if (value >= 0x20)
		{
			_value = (char)(value - 0x20);
		}
		else
		{
			_value = Emulator.nextInstruction();
			readNext = true;
		}
	}

	public String toString()
	{
		return "Value [0x" + Integer.toHexString(_value) + "]"; 
	}

	@Override
	public char getValue()
	{
		return _value;
	}

	@Override
	public void setValue(char in)
	{
		System.err.println("Access violation: assign literal");
		System.exit(3);
	}

	@Override
	public int getCycleCost()
	{
		if (readNext)
			return 1;
		return 0;
	}

	@Override
	public int getInstructionWords()
	{
		if (readNext)
			return 1;
		return 0;
	}

	@Override
	public void updateJumpAddresses()
	{
	}
	

	@Override
	public int getOpCode()
	{
		if (readNext)
			return 0x1F;
		else
			return _value + 0x20;
	}

	@Override
	public char getDataCode()
	{
		if (readNext)
			return _value;
		return 0;
	}
}
